package com.lantosec.hmrp.modules.archives.controller;


import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.archives.service.IUserEduService;
import com.lantosec.hmrp.modules.archives.vo.UserEduVO;

import java.util.Arrays;
import java.util.List;

import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 * 教育信息表 控制器
 *
 * @author AutoCode
 * @since 2020-06-09
 */
@Api(value = "教育信息表控制器", tags = "教育信息表控制器")
@RestController
@RequestMapping("/archives/user/edu")
@Log4j2
public class UserEduController extends BaseController {
    @Autowired
    private IUserEduService service;

    @GetMapping("getUserEdu/{userId}")
    @ApiOperation(value = "查询用户教育信息")
    public Result<List<UserEduVO>> getUserEdu(@ApiParam(value = "userId", required = true) @PathVariable(name = "userId") String userId) {
        List<UserEduVO> userEduVOList = service.getUserEdu(userId);
        return Result.ok(userEduVOList);
    }

    @GetMapping("getUserEduVerify/{userId}")
    @ApiOperation(value = "查询用户教育信息审核列表")
    public Result<List<UserEduVO>> getUserEduVerify(@ApiParam(value = "userId", required = true) @PathVariable(name = "userId") String userId) {
        List<UserEduVO> userEduVOList = service.getUserEduVerify(userId);
        return Result.ok(userEduVOList);
    }

    @PutMapping("verifyUserEdu")
    @ApiOperation(value = "审核")
    public Result<Void> verifyUserEdu(@ApiParam(value = "用户任职信息表VO对象", required = true) @RequestBody UserEduVO vo) {
        service.verifyUserEdu(vo);
        return Result.ok();
    }

    @GetMapping("getUserEduHistory/{userId}")
    @ApiOperation(value = "查询用户教育信息历史列表")
    public Result<List<UserEduVO>> getUserEduHistory(@ApiParam(value = "userId", required = true) @PathVariable(name = "userId") String userId) {
        List<UserEduVO> userEduVOList = service.getUserEduHistory(userId);
        return Result.ok(userEduVOList);
    }

    @PostMapping("create")
    @ControllerLog(name = "新增用户教育信息", type = LogType.add)
    @ApiOperation(value = "新增用户教育信息")
    public Result<String> create(@ApiParam(value = "教育信息表VO对象", required = true) @RequestBody @Validated UserEduVO vo) {
        service.saveUserEdu(vo);
        return Result.ok();
    }

    @PutMapping("update")
    @ControllerLog(name = "修改用户教育信息", type = LogType.update)
    @ApiOperation(value = "修改用户教育信息")
    public Result<Void> update(@ApiParam(value = "教育信息表VO对象", required = true) @RequestBody UserEduVO vo) {
        service.updateUserEdu(vo);
        return Result.ok();
    }

    @DeleteMapping(value = "delete/{ids}")
    @ControllerLog(name = "逻辑删除用户教育信息", type = LogType.delete)
    @ApiOperation("逻辑删除")
    public Result<Void> delete(@ApiParam(value = "ID列表,用逗号分隔", required = true) @PathVariable(name = "ids") String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            service.removeByIds(Arrays.asList(ids.split(",")));
        }
        return Result.ok();
    }
}
